<template name="appUpdateNotificationItem">
  <div class="notification-item">
    <div class="notification-icon">
      <img src="/apps.svg">
      {{#if senderIcon}}<img src="{{senderIcon}}">{{/if}}
      {{#if grainIcon}}<img src="{{grainIcon}}">{{/if}}
    </div>

    <div class="notification-title">
      {{_ "notifications.appUpdateNotificationItem.title"}}
    </div>

    <ul class="app-updates">
    {{#each appUpdatesList}}
      <li>{{{_ "notifications.appUpdateNotificationItem.appUpdates" name=name version=marketingVersion}}}</li>
    {{/each}}
    </ul>

    <div class="notification-footer">
      <span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
      <form class="standard-form">
        <div class="button-row">
          <button type="submit" title="{{_ "notifications.appUpdateNotificationItem.submitButton.hint"}}">{{_ "notifications.appUpdateNotificationItem.submitButton.text"}}</button>
          <button type="button" name="dismissUpdates" title="{{_ "notifications.appUpdateNotificationItem.dismissButton.hint"}}">{{_ "notifications.appUpdateNotificationItem.dismissButton.text"}}</button>
        </div>
      </form>
    </div>
  </div>
</template>

<template name="mailingListBonusNotificationItem">
{{!-- This template is only instantiated in the Blackrock deployment, but it's easier
      to all the notification templates together, since it's not really sensitive. --}}
  <div class="notification-item">
    <div class="notification-icon">
      <img src="/email.svg">
    </div>

    {{{_ "notifications.mailingListBonusNotificationItem.explanationWithBonus" (renderStorage MAILING_LIST_BONUS)}}}

    <div class="notification-footer">
      <span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
      <form class="standard-form">
        <div class="button-row">
          <button type="submit">{{_ "notifications.mailingListBonusNotificationItem.submitButton"}}</button>
          <button type="button">{{_ "notifications.mailingListBonusNotificationItem.dismissButton"}}</button>
        </div>
      </form>
    </div>
  </div>
</template>

<template name="referralNotificationItem">
  {{#linkTo route="referrals" class="notification-item"}}
    <div class="notification-icon">
    </div>

    {{#if paidUser}}
      {{_ "notifications.referralNotificationItem.paidUser"}}
    {{else}}
      {{_ "notifications.referralNotificationItem.unpaidUser"}}
    {{/if}}
    {{#linkTo route="referrals"}}
      {{_ "notifications.referralNotificationItem.link"}}
    {{/linkTo}}

    <div class="notification-footer">
      <span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
      <form class="standard-form">
        <div class="button-row">
          <button type="button">{{_ "notifications.referralNotificationItem.dismissButton"}}</button>
        </div>
      </form>
    </div>
  {{/linkTo}}
</template>

<template name="adminNotificationItem">
  <a href="{{actionTarget}}" class="notification-item {{#if isUrgent}}urgent{{/if}}">
    <div class="notification-icon">
      <img src="/sandstorm-gradient-logo.svg">
    </div>

    {{#if isType "reportStats"}}
      {{_ "notifications.adminNotificationItem.explanation"}}
    {{/if}}

    <div class="notification-footer">
      <span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
    </div>
  </a>
</template>

<template name="backgroundedGrainNotificationItem">
  {{#linkTo route="grain" class="notification-item"}}
    <div class="notification-icon">
      <img src="{{grainIcon}}">
    </div>

    <div class="notification-title">
      {{{_ "notifications.backgroundedGrainNotificationItem.title" grain=grainTitle}}}
    </div>

    {{text.defaultText}}

    <div class="notification-footer">
      <span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
      <form class="standard-form">
        <div class="button-row">
          <button title="{{_ "notifications.backgroundedGrainNotificationItem.cancelButton.hint"}}" type="button">{{_ "notifications.backgroundedGrainNotificationItem.cancelButton.text"}}</button>
        </div>
      </form>
    </div>
  {{/linkTo}}
</template>

<template name="identityChangesNotificationItem">
  <a href="https://sandstorm.io/news/2017-05-08-refactoring-identities" class="notification-item"
     target="_blank">
    <div class="notification-icon">
      <img src="/sandstorm-gradient-logo.svg">
    </div>

    {{_ "notifications.identityChangesNotificationItem.explanation"}}

    <div class="notification-footer">
      <span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
    </div>
  </a>
</template>

<template name="grainActivityNotificationItem">
  <a class="notification-item" href="{{notificationUrl}}">
    <div class="notification-icon">
      {{#if senderIcon}}<img src="{{senderIcon}}">{{/if}}
      {{#if grainIcon}}<img src="{{grainIcon}}">{{/if}}
    </div>

    <div class="notification-title">
      {{{_ "notifications.grainActivityNotificationItem.title" sender=senderName grain=grainTitle}}}
    </div>

    {{text.defaultText}} {{#if multiple}}x{{count}}{{/if}}

    <div class="notification-footer">
      <span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
      <form class="standard-form">
        <div class="button-row">
          <button type="button" title="{{_ "notifications.grainActivityNotificationItem.dismissButton.hint"}}">{{_ "notifications.grainActivityNotificationItem.dismissButton.text"}}</button>
        </div>
      </form>
    </div>
  </a>
</template>

<template name="notificationItem">
  {{!-- TODO(someday): make these be more explicitly typed, and dispatch on type.
        Ideally, allow dynamic registration of types --}}
  {{#if isAppUpdates}}
    {{> appUpdateNotificationItem . }}
  {{else}}
  {{#if isMailingListBonus }}
    {{> mailingListBonusNotificationItem . }}
  {{else}}
  {{#if isReferral}}
    {{> referralNotificationItem . }}
  {{else}}
  {{#if isAdminNotification}}
    {{> adminNotificationItem . }}
  {{else}}
  {{#if isOngoing }}
    {{> backgroundedGrainNotificationItem . }}
  {{else}}
  {{#if isIdentityChanges }}
    {{> identityChangesNotificationItem . }}
  {{else}}
    {{> grainActivityNotificationItem . }}
  {{/if}}
  {{/if}}
  {{/if}}
  {{/if}}
  {{/if}}
  {{/if}}
</template>
